package leetcode;

import java.util.HashSet;

/**
 * 描述:
 *
 * @author Madison You
 * @created 1:00
 */
public class Mid_142_DetectCycle {

    public static void main(String[] args) {

    }

    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> set = new HashSet<>();
        while (head != null) {
            if (set.contains(head)) {
                return head;
            } else {
                set.add(head);
            }
            head = head.next;
        }
        return null;
    }

}
